import request from "../utils/request.js";
import BaseResponse = API.BaseResponse;
import PageResponse = API.PageResponse;
import {JoinTeamParams, TeamSearchResponse, UpdateTeamParams} from "../modules/typing";

/**
 * 获取当前的用户
 * GET
 * /user/current
 */
export const currentUser = async (options?: {[key:string]:any}): API.BaseResponse<API.User> => {
    return await request('/user/current',{
        method: 'GET',
        ...(options || {})
    })
}

/**
 * 更新用户
 * POST
 * /user/update
 */
export const updateUser = async (body: API.UserUpdateParams, options ?: {
    [key: string]: any
}): API.BaseResponse<API.UserUpdateParams> => {
    return await request('/user/update', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        data: body,
        ...(options || {})
    })
}

/**
 * 登录
 * POST
 * /login
 */
export const login = async (body: API.LoginParams): API.BaseResponse<API.User> => {
    return await request('/user/login', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        data: body
    })
}

/**
 * 用户标签搜索
 * GET
 * /tag/search
 */
export const TagSearch = async (options?: {[key:string]:any}):BaseResponse<API.TagSearchResponse> => {
    return await request.get('/tag/search',{
        method: 'GET',
        ...(options || {})
    })
}

/**
 * 根据标签搜索用户
 * GET
 * /user/search/tags
 */
export const UserSearchByTags = async (options?: {[key:string]:any}):BaseResponse<PageResponse<API.User[]>> => {
    return await request('/user/search/tags', {
        method: 'GET',
        ...(options || {})
    })
}

/**
 * 搜索用户
 * GET
 * /user/recommend
 */
export const RecommendUsers = async (options?:{[key:string]:any}):BaseResponse<API.PageResponse<API.User[]>> => {
    return await request('/user/recommend', {
        method: 'GET',
        ...(options || {})
    })
}
/**
 * 推荐算法推荐用户
 * GET
 * /user/match
 */
export const matchUsers = async (options?:{[key:string]:any}):BaseResponse<API.PageResponse<API.User[]>> => {
    return await request('/user/match', {
        method: 'GET',
        ...(options || {})
    })
}

/**
 * 创建队伍
 * POST
 * /team
 */
export const AddTeam = async (body:API.TeamAddParams,options?: {[key:string]:any}):BaseResponse<boolean> => {
    return await request('/team',{
        method: "POST",
        headers: {
            'Content-Type': 'application/json',
        },
        data: body,
        ...(options || {})
    })
}

/**
 * 根据参数搜索队伍
 * GET
 * /team/page
 */
export const TeamSearchByCondition = async (options?: {[key:string]:any}):BaseResponse<PageResponse<API.TeamSearchResponse[]>> => {
    return await request('/team/page', {
        method: 'GET',
        ...(options || {})
    })
}

/**
 * 搜索用户 我创建的
 * GET
 * /team/page
 */
export const TeamSearchMyCreate = async (options?: {[key:string]:any}):BaseResponse<PageResponse<API.User[]>> => {
    return await request('/team/my/create', {
        method: 'GET',
        ...(options || {})
    })
}
/**
 * 搜索用户 我加入的
 * GET
 * /team/page
 */
export const TeamSearchMyJoin = async (options?: {[key:string]:any}):BaseResponse<PageResponse<API.User[]>> => {
    return await request('/team/my/join', {
        method: 'GET',
        ...(options || {})
    })
}

/**
 * 加入队伍
 * POST
 * /team/join
 * {
 *   "id": 1,
 *   "password": "1234"
 * }
 */
export const JoinTeam = async (body:API.JoinTeamParams,options?: {[key:string]:any}):BaseResponse<boolean> => {
    return await request('/team/join',{
        method: "POST",
        headers: {
            'Content-Type': 'application/json',
        },
        data: body,
        ...(options || {})
    })
}
/**
 * 修改队伍
 * PUT
 */
export const UpdateTeam = async (body:API.UpdateTeamParams,options?: {[key:string]:any}):BaseResponse<boolean> => {
    return await request('/team',{
        method: "PUT",
        headers: {
            'Content-Type': 'application/json',
        },
        data: body,
        ...(options || {})
    })
}
/**
 * 退出队伍
 * PUT
 */
export const QuitTeam = async (body:API.QuitTeamParams,options?: {[key:string]:any}):BaseResponse<boolean> => {
    return await request('/team/quit',{
        method: "DELETE",
        headers: {
            'Content-Type': 'application/json',
        },
        data: body,
        ...(options || {})
    })
}
/**
 * 解散队伍
 * PUT
 */
export const RemoveTeam = async (body:API.RemoveTeamParams,options?: {[key:string]:any}):BaseResponse<boolean> => {
    return await request('/team',{
        method: "DELETE",
        headers: {
            'Content-Type': 'application/json',
        },
        data: body,
        ...(options || {})
    })
}